package com.xuerhua.yxt.controller.sys.kccs;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xuerhua.yxt.common.RspResult;
import com.xuerhua.yxt.common.enums.Status;
import com.xuerhua.yxt.controller.BaseController;
import com.xuerhua.yxt.model.Grid;
import com.xuerhua.yxt.model.KccsSignTime;
import com.xuerhua.yxt.service.IKccsCourseInfoService;
import com.xuerhua.yxt.utils.DateUtil;

@RequestMapping("/sys/kccsCourse/endTimeConf")
@Controller
public class SysKccsEndTimeConfController extends BaseController {

	@Autowired
	private IKccsCourseInfoService kccsCourseInfoService;
	
	@RequestMapping(value={"","/"})
	public String Index() {
		return "sys/kccsCourse/endTimeConf";
	}
	
	@RequestMapping("pageQuery")
	@ResponseBody Object pageQuery(Integer schoolId){
		try {
			KccsSignTime record = kccsCourseInfoService.selectKccsEndDate(schoolId);
			List<KccsSignTime> list = new ArrayList<>();
			list.add(record);
			Grid grid = new Grid();
			grid.setRows(list);
			grid.setTotal(list.size());
			return grid;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("addUpdate")
	@ResponseBody Object addUpdate(Integer id, String endTime, String startTime){
		try {
			KccsSignTime record = new KccsSignTime();
			record.setId(id);
			record.setEndTime(DateUtil.strToDate(endTime, DateUtil.DEFAULT_DATE_FORMAT1));
			record.setStartTime(DateUtil.strToDate(startTime, DateUtil.DEFAULT_DATE_FORMAT1));
			kccsCourseInfoService.updateKccsEndDate(record);
			return new RspResult(Status.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new RspResult(Status.FAIL);
	}
	
}
